  
package com.demo.demos.demo1.controller;

import com.demo.demos.demo1.model.po.Person;
import com.demo.demos.demo1.model.query.PersonPQuery;
import com.demo.demos.demo1.service.PersonService;
import com.demo.result.PageDTO;
import com.demo.result.Result;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;



@Slf4j
@RestController
@RequestMapping("/person")
@RequiredArgsConstructor// 使用基本注解的注入形式，仅仅注入需要的变量
public class PersonController {


    private final PersonService personService;

    @PostMapping("/save")
    Result<Person> save(@RequestBody Person person) {
        Person res = personService.savePerson(person);
        return Result.success(res);
    }

    @DeleteMapping("/{id}")
    Result<String> deleteApply(@PathVariable Long id) {
        personService.removeById(id);
        return Result.success();
    }

    @GetMapping("/{id}")
    Person get(@PathVariable Long id) {
        return personService.getById(id);
    }

    @PutMapping("/put")
    Result<Person> update(@RequestBody Person person) {
        Person res =  personService.updatePersonById(person);
        return Result.success(res);
    }

    @GetMapping("/page")
    Result<PageDTO<Person>> page(PersonPQuery personQuery) {
        PageDTO<Person> pageResult = personService.pageQuery(personQuery);
        return Result.success(pageResult);
    }
}